//
//  DataHandler.m
//  AroundTheWorld
//
//  Created by IfelseGo on 16/5/15.
//  Copyright © 2016年 IfelseGo an. All rights reserved.
//

#import "DataHandler.h"
#import "AFNetworking.h"


#import "RecommendDataModel.h"

#import "CheckinModel.h"
#import "SlideModel.h"
#import "RecoummendKJNModel.h"
#import "RecoummendHotelModel.h"
#import "RecommendHotelDataCityModel.h"

#import "SubjectModel.h"
#import "SubjectMoreMoedel.h"

#import "DiscountModel.h"
#import "Discount_SubjectModel.h"
#import "DiscountMoreDataModel.h"
#import "DiscountMoreSeachDataModel.h"

#import "HotTravelNotesModel.h"
#import "HotCommentSeachModel.h"

#import "DestinationDataModel.h"
#import "CountyDataModel.h"
#import "DestnationCountryDiscountSuperModel.h"


#import "HotCommentModel.h"
#import "EnterLayoutModel.h"
#import "FindTravellingModel.h"
#import "FindTravellingMenuModel.h"


@implementation DataHandler

- (BOOL)checkNetworkingStatues
{
    //创建对象
    //reachabilityForInternetConnection 会自动获取网络状态, 并将信息存入对象中.
    Reachability *reachability = [Reachability reachabilityForInternetConnection];
    if (reachability.currentReachabilityStatus == NotReachable) {
        //无网络
        return NO;
    }else
    {
        return YES;
    }
}

//1.1(Recommend)目的地
- (void)getRecommend:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    if ([self checkNetworkingStatues]) {
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://open.qyer.com/qyer/recommands/entry?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=38.88256929626057&lon=121.5393328309779&page=1&track_app_channel=App%2520Store&track_app_version=6.8.5&track_device_info=iPhone%25205s&track_deviceid=CBF73BD2-C65E-4BC1-9574-89BDE1EE9C36&track_os=ios%25209.2.1&v=1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //拼接路径
        NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
         NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"1Recommend.plist"]];
        NSLog(@"%@",filePath);
        [responseObject writeToFile:filePath atomically:YES];
        //数据解析
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSDictionary *secondDic = [bigDic objectForKey:@"data"];
        RecommendDataModel *model = [[RecommendDataModel alloc] init];
        [model setValuesForKeysWithDictionary:secondDic];
        [modelList addObject:model];
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
    }else
    {
        //数据读取(字典)
        NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
        NSLog(@"%@",documentsPath);
        NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"1Recommend.plist"]];
        NSDictionary *resultDic = [NSDictionary dictionaryWithContentsOfFile:filePath];
//         NSArray *resultArr = [NSArray arrayWithContentsOfFile:filePath];  //读取数组时
        //数据解析
        NSDictionary *bigDic = (NSDictionary *)resultDic;
        NSMutableArray *modelList = [NSMutableArray array];
        NSDictionary *secondDic = [bigDic objectForKey:@"data"];
        RecommendDataModel *model = [[RecommendDataModel alloc] init];
        [model setValuesForKeysWithDictionary:secondDic];
        [modelList addObject:model];
        if (succeedHandler) {
            succeedHandler(modelList);
      }
    }
}



//1.2 精彩
- (void)getHotTravelNotes:(NSInteger )nextPage SucceedHandler:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler;
{
     if ([self checkNetworkingStatues]) {
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    
    //****参数cursor的值: 第一页默认为0，下一页就是请求下来数据中next_cursor的值
    //****参数count 的值: 是指定一页显示多少条数据
    NSString *str1 = @"App%2520Store";
    NSString *str2 = @"iPhone%25205s";
    NSString *str3 = @"ios%25209.3.1";
    NSInteger nextCursor = nextPage;
    NSString *url_string = [NSString stringWithFormat:@"http://open.qyer.com/qyer/recommands/trip?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=10&page=%ld&track_app_channel=%@&track_app_version=6.9.0&track_device_info=%@&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=%@&type=index&v=1",nextCursor,str1,str2,str3];
//    NSLog(@"nextcunrsor=========2 ======= %ld",nextCursor);
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    [manager GET:url_string parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //拼接路径
        NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
        NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"1HotTravel.plist"]];
        NSLog(@"%@",filePath);
        [responseObject writeToFile:filePath atomically:YES];

        //数据解析
        [netWorkManager stopMonitoring];
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
       for (NSDictionary *dic in arrayTemp) {
           HotTravelNotesModel *model = [[HotTravelNotesModel alloc] init];
           [model setValuesForKeysWithDictionary:dic];
           [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
  }else
     {
         //数据读取(字典)
         NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
         NSLog(@"%@",documentsPath);
         NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"1HotTravel.plist"]];
         NSDictionary *resultDicA = [NSDictionary dictionaryWithContentsOfFile:filePath];
         
         NSDictionary *bigDic = (NSDictionary *)resultDicA;
         NSMutableArray *modelList = [NSMutableArray array];
         NSArray *arrayTemp = [bigDic objectForKey:@"data"];
         for (NSDictionary *dic in arrayTemp) {
             HotTravelNotesModel *model = [[HotTravelNotesModel alloc] init];
             [model setValuesForKeysWithDictionary:dic];
             [modelList addObject:model];
             
         }
         if (succeedHandler) {
             succeedHandler(modelList);
         }
     }
}

//1.1.1 看锦囊
- (void)getRecoummendKJNNotes:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://open.qyer.com/qyer/guide/category_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&oauth_token=aa2b598eae24c66826dc4e4ba1cacc76&page=1&track_app_channel=App%2520Store&track_app_version=6.9.0&track_device_info=iPhone%25205s&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=ios%25209.3.1&track_user_id=7907956&v=1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in arrayTemp) {
            RecoummendKJNModel *model = [[RecoummendKJNModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}
//1.1.1(明细) 看锦囊--明细 ?????????
- (void)getRecoummendKJNDataNotes:(NSString *)kjnID SucceedHandler:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *str1 = @"App%2520Store";
    NSString *str2 = @"iPhone%25205s";
    NSString *str3 = @"ios%25209.3.1";
    
    
    [manager GET:[NSString stringWithFormat: @"http://open.qyer.com/qyer/guide/channel_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&id=%@&oauth_token=aa2b598eae24c66826dc4e4ba1cacc76&page=1&track_app_channel=%@&track_app_version=6.9.0&track_device_info=%@&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=%@&track_user_id=7907956&v=1",kjnID,str1,str2,str3] parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in arrayTemp) {
            RecoummendKJNMDataodel *model = [[RecoummendKJNMDataodel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}


//1.1.2(明细)  - 1 订酒店--明细
- (void)getRecoummendHotelDataNotes:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://open.qyer.com/qyer/hotel/hot_city_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=9&page=1&track_app_channel=App%2520Store&track_app_version=6.9.0&track_device_info=iPhone%25205s&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=ios%25209.3.1&v=1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in arrayTemp) {
            RecoummendHotelModel *model = [[RecoummendHotelModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}
//1.1.2(明细) - 2 订酒店--选择城市
- (void)getRecoummendHotelDataCityNotes:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://open.qyer.com/qyer/hotel/hot_city_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=199&lat=48.856613&lon=2.352222&oauth_token=aa2b598eae24c66826dc4e4ba1cacc76&page=1&track_app_channel=App%2520Store&track_app_version=6.9.0&track_device_info=iPhone%25205s&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=ios%25209.3.1&track_user_id=7907956&v=1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in arrayTemp) {
            RecommendHotelDataCityModel *model = [[RecommendHotelDataCityModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}


//1.1.3 查看更多精彩专题
- (void)getSubjectMoreNotes:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://open.qyer.com/qyer/special/topic/special_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&page=1&track_app_channel=App%2520Store&track_app_version=6.8.5&track_device_info=iPhone%25205s&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=ios%25209.3.1&v=1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in arrayTemp) {
            SubjectMoreMoedel *model = [[SubjectMoreMoedel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}

//1.1.4 查看全部特价折扣
- (void)getDiscountMoreNotes:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://open.qyer.com/qyer/discount/zk/discount_index?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&page=1&track_app_channel=App%2520Store&track_app_version=6.9.0&track_device_info=iPhone%25205s&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=ios%25209.3.1&v=1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSDictionary *dicTemp = [bigDic objectForKey:@"data"];
        DiscountMoreDataModel *model = [[DiscountMoreDataModel alloc] init];
        [model setValuesForKeysWithDictionary:dicTemp];
        [modelList addObject:model];
          if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}


//1.1.4-2 查看全部特价折扣---搜索后Data
- (void)getDiscountMoreDataNotes:(NSString *)contryName SucceedHandler:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *str1 = @"App%2520Store";
    NSString *str2 = @"iPhone%25205s";
    NSString *str3 = @"ios%25209.3.1";
    
    [manager GET:[NSString stringWithFormat:@"http://open.qyer.com/qyer/discount/zk/search_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&keyword=%@&lat=41.890518&lon=12.494249&order=1&page=1&track_app_channel=%@&track_app_version=6.9.0&track_device_info=%@&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=%@&v=1", contryName, str1, str2, str3] parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSDictionary *dicTemp = [bigDic objectForKey:@"data"];
        DiscountMoreSeachDataModel *model = [[DiscountMoreSeachDataModel alloc] init];
        [model setValuesForKeysWithDictionary:dicTemp];
        [modelList addObject:model];
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}

// 搜索
- (void)getSearchHistory:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://open.qyer.com/qyer/search/hot_history?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=35.689487&lon=139.691711&page=1&track_app_channel=App%2520Store&track_app_version=6.9.0&track_device_info=iPhone%25205s&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=ios%25209.3.1&v=1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSArray *list = [bigDic objectForKey:@"data"];
        
        if (succeedHandler) {
            succeedHandler(list);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}

//2.1.1(Destination)推荐
- (void)getDestinationBase:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    if ([self checkNetworkingStatues]) {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://open.qyer.com/qyer/footprint/continent_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=38.88250864194671&lon=121.5393777429208&oauth_token=51c16ac42c049d7967cec9579b89a89d&page=1&track_app_channel=App%2520Store&track_app_version=6.8.5&track_device_info=iPhone%25205s&track_deviceid=CBF73BD2-C65E-4BC1-9574-89BDE1EE9C36&track_os=ios%25209.2.1&track_user_id=7664574&v=1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //创建路径
        NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
        NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"2Destination.plist"]];
        NSLog(@"%@",filePath);
        [responseObject writeToFile:filePath atomically:YES];
        
        //数据解析
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in arrayTemp) {
            DestinationDataModel *model = [[DestinationDataModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
    }else{
        //数据读取(字典)
        NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
        NSLog(@"%@",documentsPath);
        NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"2Destination.plist"]];
        NSDictionary *resultDic = [NSDictionary dictionaryWithContentsOfFile:filePath];
        //         NSArray *resultArr = [NSArray arrayWithContentsOfFile:filePath];  //读取数组时
        //数据解析
        NSDictionary *bigDic = (NSDictionary *)resultDic;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in arrayTemp) {
            DestinationDataModel *model = [[DestinationDataModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }

    }
}


//2.2.1(Destination  - County)国家
- (void)getDestinationCounty:(NSString *)countyID succeedHandler:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *temp1 = @"App%2520Store";
    NSString *temp2 = @"iPhone%25205s";
    NSString *temp3 = @"ios%25209.3.1";
    
    NSString *url = [NSString stringWithFormat:@"http://open.qyer.com/qyer/footprint/country_detail?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&country_id=%@&page=1&track_app_channel=%@&track_app_version=6.8.5&track_device_info=%@&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=%@&v=1",countyID,temp1, temp2, temp3];
    
    
    [manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSDictionary *dicTemp = [bigDic objectForKey:@"data"];
        CountyDataModel *model = [[CountyDataModel alloc] init];
        [model setValuesForKeysWithDictionary:dicTemp];
        [modelList addObject:model];
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];

}

//http://open.qyer.com/qyer/discount/tickets_freewalker?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&id=236&order=2&page=1&product_type=1016%2C1018%2C1020&time=1&track_app_channel=App%2520Store&track_app_version=6.8.5&track_device_info=iPhone%25205s&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=ios%25209.3.1&type=1&v=1

//2.3.1(Destination  - County DiscountSuper)国家
- (void)getDestinationCountyDiscountSuper:(NSString *)countyID succeedHandler:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *temp1 = @"App%2520Store";
    NSString *temp2 = @"iPhone%25205s";
    NSString *temp3 = @"ios%25209.3.1";
    NSString *temp4 = @"1016%2C1018%2C1020&time";
    
    NSString *url = [NSString stringWithFormat:@"http://open.qyer.com/qyer/discount/tickets_freewalker?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&id=%@&order=2&page=1&product_type=%@=1&track_app_channel=%@&track_app_version=6.8.5&track_device_info=%@&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=%@&type=1&v=1",countyID,temp1, temp4, temp2, temp3];
    
    [manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSDictionary *dicTemp = [bigDic objectForKey:@"data"];
        NSMutableArray *arrayTemp = [dicTemp objectForKey:@"list"];
        for (NSDictionary *dic in arrayTemp) {
            DestnationCountryDiscountSuperModel *model = [[DestnationCountryDiscountSuperModel alloc] init];
     
        [model setValuesForKeysWithDictionary:dic];
        [modelList addObject:model];
    }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}

//http://open.qyer.com/qyer/discount/local_discount?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&id=11&lat=35.689487&lon=139.691711&order=2&page=1&product_type=2410&time=1&track_app_channel=App%2520Store&track_app_version=6.9.0&track_device_info=iPhone%25205s&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=ios%25209.3.1&type=1&v=1

//2.3.2(Destination  - County DiscountWonderful)国家
- (void)getDestinationCountyDiscountWonderful:(NSString *)countyID succeedHandler:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *temp1 = @"App%2520Store";
    NSString *temp2 = @"iPhone%25205s";
    NSString *temp3 = @"ios%25209.3.1";
    
    NSString *url = [NSString stringWithFormat:@"http://open.qyer.com/qyer/discount/local_discount?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&id=%@&lat=35.689487&lon=139.691711&order=2&page=1&product_type=2410&time=1&track_app_channel=%@&track_app_version=6.9.0&track_device_info=%@&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=%@&type=1&v=1",countyID, temp1, temp2, temp3];
    
    [manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSDictionary *dicTemp = [bigDic objectForKey:@"data"];
        NSMutableArray *arrayTemp = [dicTemp objectForKey:@"list"];
        for (NSDictionary *dic in arrayTemp) {
            DestnationCountryDiscountSuperModel *model = [[DestnationCountryDiscountSuperModel alloc] init];
            
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}






//3.1.1(Destination)社区 热议-- 刷新多页的
- (void)getCommunityBase:(NSInteger )nextPage SucceedHandler:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    
    if ([self checkNetworkingStatues]) {
     AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        NSString *str1 = @"App%2520Store";
        NSString *str2 = @"iPhone8%2C1";
        NSString *str3 = @"ios%25209.3.1";
    [manager GET:[NSString stringWithFormat:@"http://open.qyer.com/qyer/community/hotbbs/index?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=10&lat=38.88283798007659&lon=121.539156053574&oauth_token=4ea07b0d41e13f5cb1448a45a3613e45&page=%ld&track_app_channel=%@&track_app_version=6.9.0&track_device_info=%@&track_deviceid=F417850E-117E-4BF4-AAA6-3AD14E14E3C1&track_os=%@&track_user_id=7891151&v=1", nextPage, str1, str2, str3] parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
     //创建路径
     NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
     NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"3CommunityDestination.plist"]];
     NSLog(@"%@",filePath);
     [responseObject writeToFile:filePath atomically:YES];
     
        //数据解析
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in arrayTemp) {
            HotCommentModel *model = [[HotCommentModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
    } else{
        //数据读取(字典)
        NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
        NSLog(@"%@",documentsPath);
        NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"3CommunityDestination.plist"]];
        NSDictionary *resultDic = [NSDictionary dictionaryWithContentsOfFile:filePath];
        //数据解析
        NSDictionary *bigDic = (NSDictionary *)resultDic;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in arrayTemp) {
            HotCommentModel *model = [[HotCommentModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    }
}

//3.1.2(Destination)社区 热议-- 搜索
//http://open.qyer.com/qyer/search/index?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&keyword=美国&lat=35.689487&lon=139.691711&page=1&place_field=country%7Ccity%7Cpoi&track_app_channel=App%2520Store&track_app_version=6.9.0&track_device_info=iPhone%25205s&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=ios%25209.3.1&type=thread&v=1
- (void)getCommunityHotCommentSeachDataNotes:(NSString *)contryName SucceedHandler:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    NSString *str1 = @"App%2520Store";
    NSString *str2 = @"country%7Ccity%7Cpoi";
    NSString *str3 = @"ios%25209.3.1";
     NSString *str4 = @"iPhone%25205s";
    
    [manager GET:[NSString stringWithFormat:@"http://open.qyer.com/qyer/search/index?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&keyword=%@&lat=35.689487&lon=139.691711&page=1&place_field=%@&track_app_channel=%@&track_app_version=6.9.0&track_device_info=%@&track_deviceid=E3EBA485-00FA-421D-BACB-D791AF3400E2&track_os=%@&type=thread&v=1", contryName, str1, str2,str4, str3] parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSDictionary *dicTemp = [bigDic objectForKey:@"data"];
        
        for (NSDictionary *dic in [dicTemp objectForKey:@"entry"]) {
            HotCommentSeachModel *model = [[HotCommentSeachModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}




//3.2.1(Destination)社区 进入版面
- (void)getCommunityEnterLayoutBase:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    if ([self checkNetworkingStatues]) {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://open.qyer.com/qyer/bbs/entry?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=38.88283798007659&lon=121.539156053574&oauth_token=4ea07b0d41e13f5cb1448a45a3613e45&page=1&track_app_channel=App%2520Store&track_app_version=6.9.0&track_device_info=iPhone8%2C1&track_deviceid=F417850E-117E-4BF4-AAA6-3AD14E14E3C1&track_os=ios%25209.3.1&track_user_id=7891151&v=1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //创建路径
        NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
        NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"3CommunityEnterLayout.plist"]];
        NSLog(@"%@",filePath);
        [responseObject writeToFile:filePath atomically:YES];
        
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSDictionary *dicTemp = [bigDic objectForKey:@"data"];
            EnterLayoutModel *model = [[EnterLayoutModel alloc] init];
            [model setValuesForKeysWithDictionary:dicTemp];
            [modelList addObject:model];
       
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
    }else
    {
        //数据读取(字典)
        NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
        NSLog(@"%@",documentsPath);
        NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"3CommunityEnterLayout.plist"]];
        NSDictionary *resultDic = [NSDictionary dictionaryWithContentsOfFile:filePath];
        //数据解析
        NSDictionary *bigDic = (NSDictionary *)resultDic;
        NSMutableArray *modelList = [NSMutableArray array];
        NSDictionary *dicTemp = [bigDic objectForKey:@"data"];
        EnterLayoutModel *model = [[EnterLayoutModel alloc] init];
        [model setValuesForKeysWithDictionary:dicTemp];
        [modelList addObject:model];
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    }
}


//3.3.1(Destination)社区 找旅伴
- (void)getCommunityFindTravellBase:(NSInteger )nextPage SucceedHandler:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    if ([self checkNetworkingStatues]) {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        NSString *str1 = @"App%2520Store";
        NSString *str2 = @"iPhone8%2C1";
        NSString *str3 = @"ios%25209.3.1";
    [manager GET:[NSString stringWithFormat:@"http://open.qyer.com/qyer/company/search_list?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=38.88283798007659&lon=121.539156053574&oauth_token=4ea07b0d41e13f5cb1448a45a3613e45&page=%ld&track_app_channel=%@&track_app_version=6.9.0&track_device_info=%@&track_deviceid=F417850E-117E-4BF4-AAA6-3AD14E14E3C1&track_os=%@&track_user_id=7891151&v=1", nextPage, str1, str2, str3] parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //创建路径
        NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
        NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"3CommunityEnterLayout.plist"]];
        NSLog(@"%@",filePath);
        [responseObject writeToFile:filePath atomically:YES];
        //数据解析
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in arrayTemp) {
            FindTravellingModel *model = [[FindTravellingModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
    }else
    {
        //数据读取(字典)
        NSString *documentsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).lastObject;
        NSLog(@"%@",documentsPath);
        NSString *filePath = [documentsPath stringByAppendingPathComponent:[NSString stringWithFormat:@"3CommunityEnterLayout.plist"]];
        NSDictionary *resultDic = [NSDictionary dictionaryWithContentsOfFile:filePath];
        //数据解析
        NSDictionary *bigDic = (NSDictionary *)resultDic;
        NSMutableArray *modelList = [NSMutableArray array];
        NSArray *arrayTemp = [bigDic objectForKey:@"data"];
        for (NSDictionary *dic in arrayTemp) {
            FindTravellingModel *model = [[FindTravellingModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [modelList addObject:model];
        }
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    }
}


//3.3.2(Destination)社区 找旅伴 -- 查找条件
- (void)getCommunityFindTravellMenuBase:(SucceedHandler)succeedHandler failedHandler:(FailedHandler)failedHandler
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    [manager GET:@"http://open.qyer.com/qyer/community/company/filter?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&lat=38.88283798007659&lon=121.539156053574&oauth_token=4ea07b0d41e13f5cb1448a45a3613e45&page=1&track_app_channel=App%2520Store&track_app_version=6.9.0&track_device_info=iPhone8%2C1&track_deviceid=F417850E-117E-4BF4-AAA6-3AD14E14E3C1&track_os=ios%25209.3.1&track_user_id=7891151&v=1" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *bigDic = (NSDictionary *)responseObject;
        NSMutableArray *modelList = [NSMutableArray array];
        NSDictionary *dicTemp = [bigDic objectForKey:@"data"];
        FindTravellingMenuModel *model = [[FindTravellingMenuModel alloc] init];
        [model setValuesForKeysWithDictionary:dicTemp];
        [modelList addObject:model];
        
        if (succeedHandler) {
            succeedHandler(modelList);
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        if (failedHandler) {
            failedHandler(error);
        }
    }];
}


@end
